/**
 * Created by novem on 15/9/25.
 */
window.onload=function(){
    var url = getUrl();
    var userId = getUserId();
    var id= $.getUrlParam("id");
    $.jsonp({
        url: 'http://'+url+'/api/order/order_detail-' + id,
        data: {},
        callbackParameter: "callback",
        success: function (data, textStatus, xOptions) {
            var complied_tpl = juicer($("#order").text());
            var html = complied_tpl.render(data);
            $(".order-list").append(html);
        },
        error: function (xOptions, textStatus) {
        }
    });
    $(".ui-header-right").on("click", function () {
        var star= $("#star li.on").length;
        var comment = $("#comment").val();
        var urlList = getPics();
        var param = $.getUrlParam("param");
        if(star == 0){
            showToast("总体评价需要打分哦~");
            return;
        }
        if(comment == ""){
            showToast("点评内容不能为空哦~");
            return;
        }
        //if(urlList == ""){
        //    showToast("请至少上传一张图片~");
        //    return;
        //}
        if(comment.length<=20){
            $.jsonp({
                url: 'http://'+url+'/api/supplier/comment',
                data: {star:star,comment:comment,orderId:id,urlList:urlList,userId:userId},
                callbackParameter: "callback",
                success: function (data, textStatus, xOptions) {
                   console.log(data)
                    if(data.succ==true){
                        //alert("111")
                        showToast("评论成功~");
                        window.history.go(-1);
                    }else{
                        //alert("222")
                        showToast("评论失败~");
                    }
                },
                error: function (xOptions, textStatus) {
                    showToast("评论失败~");
                }
            });
        }
        else{
            showToast("点评内容不能超过20个字~");
            return;
        }

    });
    var oStar = document.getElementById("star");
    var aLi = oStar.getElementsByTagName("li");
    var oUl = oStar.getElementsByTagName("ul")[0];
    for (i = 1; i <= aLi.length; i++){
        aLi[i - 1].index = i;
        //鼠标移过显示分数
        aLi[i - 1].onmouseover = function (){
            fnPoint(this.index);
        };
    }
    //评分处理
    function fnPoint(iArg){
        //分数赋值
        iScore = iArg ;
        for (i = 0; i < aLi.length; i++) aLi[i].className = i < iScore ? "on" : "";
    }

}